var $_GET = (function () {
    var url = window.document.location.href.toString();
    var u = url.split("?");
    if (typeof (u[1]) == "string") {
        u = u[1].split("&");
        var get = {};
        for (var i in u) {
            var j = u[i].split("=");
            get[j[0]] = j[1];
        }
        return get;
    } else {
        return {};
    }
})();

$("#submit_cart").click(function () {
    var gid = $("#gootsp").attr('data-gid');
    var count = $("#gootsp").attr('data-count');
    if (gid == '' || count == '') {
        layer.alert('数据异常,缺失重要数据');
        return false;
    }
    if ($("#num").val() <= 0) {
        layer.alert('下单份数不可低于1份', {icon: 2, anim: 4});
        return false;
    }
    var arr = [];
    var b = 1;
    var conts = '';
    for (let a = 0; a < count; a++) {
        arr[a] = $("#input_val_" + b).val();
        if (arr[a] == '') {
            layer.alert('请把' + $("#var_c" + b).text() + '填写完整哦！');
            return false;
        }
        var inputes = arr[a];
        var namevar = $("#var_c" + b).text();
        checkInput("var_c" + b, 'input_val_' + b);
        if ((namevar == '下单ＱＱ' || namevar == 'ＱＱ账号' || namevar == 'QQ账号' || namevar == '下单QQ') && (inputes.length < 5 || inputes.length > 11 || isNaN(inputes))) {
            layer.alert('请输入正确的ＱＱ号！');
            return false;
        }
        var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
        if (namevar == '你的邮箱' && !reg.test(inputes)) {
            layer.alert('邮箱格式不正确！');
            return false;
        }
        reg = /^[1][0-9]{10}$/;
        if (namevar == '手机号码' && !reg.test(inputes)) {
            layer.alert('手机号码格式不正确！');
            return false;
        }

        if (namevar == '说说ID' || namevar == '说说ＩＤ') {
            if (inputes.length != 24) {
                layer.alert('说说必须是原创说说！');
                return false;
            }
        }
        if (namevar == '抖音作品ID' || namevar == '火山作品ID' || namevar == '火山直播ID') {
            if (inputes.length != 19) {
                layer.alert('您输入的作品ID有误！');
                return false;
            }
        }
        if (namevar == '抖音评论ID' || namevar == '抖音ID') {
            if (inputes.length != 19) {
                layer.alert('您输入的评论ID有误！请点击自动获取手动选择评论！');
                return false;
            }
        }

        conts += $("#var_c" + b).text() + '：' + arr[a] + ' ';
        b = b + 1;
    }
    num = $("#num").val();
    if (num == '') {
        num = 1;
    }

    var indexs = layer.load(3, {time: 9666699});
    $.ajax({
        type: "post",
        url: "ajax.php?act=CartAdd",
        data: {gid: gid, data: arr, num: num, conts: conts},
        dataType: "json",
        success: function (data) {
            layer.close(indexs);
            if (data.code == 1) {
                $("#cart_sum").html(' (' + data.count + ')');
                var inst = layer.msg(data.msg, {
                    btn: ['去结算', '再逛逛'], time: 999999, btn1: function (layero, index) {
                        if (window.innerWidth > 460) {
                            area = ['460px', '90%'];
                            layer.closeAll();
                            layer.open({
                                title: '我的购物车',
                                type: 2,
                                shade: false,
                                area: area,
                                maxmin: true,
                                skin: 'layui-layer-rim',
                                content: '/?mod=cart',
                                zIndex: 9999999, //重点1
                                success: function (layero) {
                                    layer.iframeAuto();
                                }
                            });
                        } else {
                            window.location.href = '?mod=cart';
                        }
                    },
                    btn2: function (layero, index) {
                        layer.close(inst);
                    }
                })
            } else {
                layer.msg(data.msg, {icon: 2});
            }
        },
        error: function () {
            layer.alert('加载失败！');
        }
    });


});

$("#submit").click(function () {
    var gid = $("#gootsp").attr('data-gid');
    var count = $("#gootsp").attr('data-count');
    if (gid == '' || count == '') {
        layer.alert('数据异常,缺失重要数据');
        return false;
    }
    if ($("#num").val() <= 0) {
        layer.alert('下单份数不可低于1份', {icon: 2, anim: 4});
        return false;
    }
    var arr = [];
    var b = 1;
    var conts = '';
    for (let a = 0; a < count; a++) {
        arr[a] = $("#input_val_" + b).val();
        if (arr[a] == '') {
            layer.alert('请把' + $("#var_c" + b).text() + '填写完整哦！');
            return false;
        }
        var inputes = arr[a];
        var namevar = $("#var_c" + b).text();
        checkInput("var_c" + b, 'input_val_' + b);
        if ((namevar == '下单ＱＱ' || namevar == 'ＱＱ账号' || namevar == 'QQ账号' || namevar == '下单QQ') && (inputes.length < 5 || inputes.length > 11 || isNaN(inputes))) {
            layer.alert('请输入正确的ＱＱ号！');
            return false;
        }
        var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
        if (namevar == '你的邮箱' && !reg.test(inputes)) {
            layer.alert('邮箱格式不正确！');
            return false;
        }
        reg = /^[1][0-9]{10}$/;
        if (namevar == '手机号码' && !reg.test(inputes)) {
            layer.alert('手机号码格式不正确！');
            return false;
        }

        if (namevar == '说说ID' || namevar == '说说ＩＤ') {
            if (inputes.length != 24) {
                layer.alert('说说必须是原创说说！');
                return false;
            }
        }
        if (namevar == '抖音作品ID' || namevar == '火山作品ID' || namevar == '火山直播ID') {
            if (inputes.length != 19) {
                layer.alert('您输入的作品ID有误！');
                return false;
            }
        }
        if (namevar == '抖音评论ID' || namevar == '抖音ID') {
            if (inputes.length != 19) {
                layer.alert('您输入的评论ID有误！请点击自动获取手动选择评论！');
                return false;
            }
        }

        conts += '<div>' + $("#var_c" + b).text() + '：' + arr[a] + '</div>';
        b = b + 1;
    }
    num = $("#num").val();
    if (num == '') {
        num = 1;
    }
    var indexs = layer.load(3, {time: 9666699});
    $.ajax({
        type: "post",
        url: "ajax.php?act=orders_transit",
        data: {gid: gid, data: arr, num: num, conts: conts},
        dataType: "json",
        success: function (data) {
            layer.close(indexs);
            if (data.code == 1) {
                location.href = data.url;
                setTimeout(function () {
                    layer.alert('<font size="4" color="#2e8b57">若未跳转付款界面,请点击下方付款按钮！</font>', {
                        title: '温馨提示!',
                        btn: ['付款'], time: 9999999, btn1: function (layero, index) {
                            location.href = data.url;
                        }
                    })
                }, 500);
            } else {
                layer.msg(data.msg, {icon: 2});
            }
        },
        error: function () {
            layer.alert('加载失败！');
        }
    });
});

$("#submit_query").click(function () {
    merchandise.query_sep($('#vae').val())
});

//订单管理(新)
var OrderManagement = {
    OrderQuery: function (type, msg = null) { //查询全部订单
        var load = layer.load(2);
        $.ajax({
            type: "post",
            url: "/ajax.php?act=OrderQuery",
            data: {
                type: type,
                msg: msg
            },
            dataType: "json",
            success: function (data) {
                layer.close(load);
                template.query_tem(data);
            },
            error: function () {
                layer.alert('加载失败！');
            }
        });
    },
};

/**
 * 下单所需参数构建
 * @type {{gid_data: merchandise.gid_data, GoodsMonitoring: merchandise.GoodsMonitoring, query_data: merchandise.query_data, shop_data: merchandise.shop_data, query_goods: merchandise.query_goods, get_data: merchandise.get_data, cid_data: merchandise.cid_data}}
 */
var merchandise = {
    query_sep: function (val) {
        if (val == '') {
            layer.alert('请填写完整', {icon: 2});
            return false;
        }
        var index = layer.msg('正在查询中...', {icon: 16, time: 9999999});
        $.ajax({
            type: "post",
            url: "/ajax.php?act=OrderQuery",
            data: {msg: val, type: 'QueryList'},
            dataType: "json",
            success: function (data) {
                layer.close(index);
                if (data.code == 1) {
                    if (data.data.length == 0) {
                        layer.msg('没有查询到相关数据！');
                        layer.close(index);
                        return false;
                    }

                    var content = '<div style="overflow:auto;padding: 0.1em;max-height: 80vh"><table class="layui-table" lay-skin="row" lay-size="sm" style="white-space:nowrap"><thead><tr><th>操作</th><th>订单ID</th><th>状态</th><th>下单信息</th><th>商品名称</th><th>时间</th></tr></thead><tbody id="tabte">';

                    $.each(data.data, function (index, item) {
                        console.log(index);
                        switch (item.state) {
                            case '1':
                                var state = '<span class="layui-badge" style="background-color: #00E676">已完成</span>';
                                break;
                            case '2':
                                var state = '<span class="layui-badge" style="background-color: #40C4FF">待处理</span>';
                                break;
                            case '3':
                                var state = '<span class="layui-badge" style="background-color: #FF5252">异常中</span>';
                                break;
                            case '4':
                                var state = '<span class="layui-badge" style="background-color: #FFD54F">处理中</span>';
                                break;
                            case '5':
                                var state = '<span class="layui-badge" style="background-color: #A6A6A6">已退款</span>';
                                break;
                            default:
                                var state = '<span class="layui-badge" style="background-color: #757575">未知状态</span>';
                                break;
                        }
                        if (item.input == null) {
                            item.input = '未填写';
                        }
                        content += '<tr><td  onclick="merchandise.query_data(' + item.id + ')"><span class="layui-badge" style="background-color: #AB47BC">详情</span></td><td>' + item.id + '</td><td>' + state + '</td><td>' + item.input + '</td><td>' + item.name + '</td><td>' + item.addtitm + '</td></tr>';
                    });
                    content += '</tbody></table></div>';
                    console.log(content);
                    var area = [$(window).width() > 460 ? '648' : '90%'];
                    var indexs = layer.open({
                        type: 1,
                        title: '订单列表',
                        content: content,
                        area: area,
                        offset: '50px',
                    });
                } else layer.msg(data.msg);
            },
            error: function () {
                layer.alert('服务器链接失败!');
                layer.close(index);
            }
        });
    },
    tickets: function (id = null) {
        layer.open({
            type: 2,
            area: ['98%', '98%'],
            title: '售后工单[' + id + ']',
            content: '/user/tickets_new.php?id=' + id,
            skin: 'layui-layer-rim',
            id: 'OrderMark',
            btn: false
        });
    },
    mark: function (id) {
        var area = [$(window).width() > 480 ? '480px' : '98%', '93%'];
        layer.open({
            type: 2,
            area: area,
            title: '评论内容',
            content: '/?mod=evaluate&gid=' + id,
            skin: 'layui-layer-rim',
            id: 'extract',
            btn: false
        });
    },
    query_mark: function (id = null) {
        var area = [$(window).width() > 480 ? '480px' : '98%', '93%'];
        layer.open({
            type: 2,
            area: area,
            title: '发表评论',
            content: '/?mod=OrderMark&id=' + id,
            skin: 'layui-layer-rim',
            id: 'OrderMark',
            btn: false,
            end: function (layero, index) {
                OrderManagement.OrderQuery('OrderAll');
            }
        });
    },
    query_delete: function (id) {
        layer.open({
            title: '温馨提示',
            content: '是否要删除订单[' + id + ']?,删除后无法找回,且无法进行售后!',
            btn: ['确认无误,我要删除', '取消'],
            icon: 2,
            btn1: function (layero, index) {
                $.ajax({
                    type: "post",
                    url: "/ajax.php?act=OrderQuery&type=QueryDelete",
                    data: {
                        id: id
                    },
                    dataType: "json",
                    success: function (data) {
                        if (data.code == 1) {
                            layer.alert(data.msg, {
                                icon: 1, title: '温馨提示', end: function (layero, index) {
                                    OrderManagement.OrderQuery('OrderAll');
                                }
                            });
                        } else {
                            layer.msg(data.msg, {icon: 2});
                        }
                    },
                    error: function () {
                        layer.alert('加载失败！');
                    }
                });
            }
        });
    },
    query_take: function (id) {
        layer.open({
            title: '温馨提示',
            content: '是否确认收货,收货后可评价此商品订单哦!',
            btn: ['确认', '取消'],
            icon: 3,
            btn1: function (layero, index) {
                $.ajax({
                    type: "post",
                    url: "/ajax.php?act=OrderQuery&type=QueryTake",
                    data: {
                        id: id
                    },
                    dataType: "json",
                    success: function (data) {
                        if (data.code == 1) {
                            layer.alert(data.msg, {
                                icon: 1, title: '温馨提示', btn: ['评价', '关闭'], btn1: function (layero, index) {
                                    layer.closeAll();
                                    merchandise.query_mark(id);
                                }, end: function (layero, index) {
                                    OrderManagement.OrderQuery('OrderAll');
                                }
                            });
                        } else {
                            layer.msg(data.msg, {icon: 2});
                        }
                    },
                    error: function () {
                        layer.alert('加载失败！');
                    }
                });
            }
        });
    },
    query_goods: function (name) {
        location.href = '?name=' + name;
    },
    get_data: function (gid, arr, type, mode = null) {
        var paytype = $("input[name=pay]:checked").val();
        var order = JSON.parse($("body").attr('order'));
        mode = 'alipay';
        type = 1;
        if (paytype == undefined) {
            swal({
                title: '注意',
                type: 'warning',
                html: '<h4>请选择付款方式！</h4>',
                confirmButtonText: '好的',
            });
            return false;
        }
        switch (paytype) {
            case '1'://支付宝
                mode = 'alipay';
                break;
            case '2': //微信
                mode = 'wxpay';
                break;
            case '3': //QQ
                mode = 'qqpay';
                break;
            case '4': //余额
                type = 2;
                break;
            case '5': //积分
                type = 3;
                break;
            case '6':
                //demo_url
                var content = $("#demo_url").attr('data-url');
                var clipboard = new Clipboard('.btssn', {
                    text: function () {
                        return content;
                    }
                });
                layer.open({
                    title: '代付订单创建成功',
                    btn: false,
                    content: '<center style="color: seagreen">代付订单已经创建成功，发给好友帮你付款吧~</center><hr><textarea  class="layui-textarea">' + content + '</textarea><hr>' +
                        '<center><button class="layui-btn layui-btn-fluid layui-btn-radius layui-btn-sm layui-btn-normal btssn">点击复制</button></center>',
                });
                clipboard.on('success', function (e) {
                    swal({
                        title: '恭喜',
                        type: 'success',
                        html: '代付订单链接已经帮您复制到剪切板上啦，快去发送给朋友让他帮你付款吧~',
                        confirmButtonText: '好的',
                    });
                    layer.closeAll();
                });
                clipboard.on('error', function (e) {
                    console.log(e);
                    swal({
                        title: '异常',
                        type: 'warning',
                        html: '复制功能好像出了点问题，去手动复制代付订单链接发给朋友吧',
                        confirmButtonText: '好的',
                    });
                    layer.closeAll();
                });
                return false;
                break;
        }
        var index = layer.msg('加载中...', {icon: 16, time: 9999999});
        $.ajax({
            type: "post",
            url: "ajax.php?act=submit_input",
            data: {type: type, mode: mode, orders: order},
            dataType: "json",
            success: function (data) {
                layer.close(index);
                if (data.code == 1) {
                    if (data.khamwi != undefined) {
                        var kam = '';
                        for (let a = 0; a < data.khamwi.length; a++) {
                            kam += '<br>卡' + (a + 1) + '：' + data.khamwi[a];
                        }
                        layer.alert('您的卡密内容为：' + kam, {
                            title: data.msg,
                            icon: 1, btn1: function (layero, index) {
                                location.href = '/?mod=query';
                            }
                        });
                    } else {
                        layer.alert(data.msg, {
                            icon: 1, btn1: function (layero, index) {
                                location.href = '/?mod=query';
                            }
                        });
                    }
                } else if (data.code == 2) {
                    location.href = data.url;
                    setTimeout(function () {
                        layer.alert('<font size="4" color="#2e8b57">若未跳转付款界面,请点击下方付款按钮！</font>', {
                            title: '温馨提示!',
                            btn: ['付款'], time: 9999999, btn1: function (layero, index) {
                                location.href = data.url;
                            }
                        })
                    }, 500);
                } else if (data.code == -3) { //返回首页
                    layer.alert(data.msg, {
                        icon: 2, end: function (layero, index) {
                            location.href = '/'
                        }
                    });
                } else if (data.code == -2) { //进入后台
                    layer.alert(data.msg, {
                        icon: 2, end: function (layero, index) {
                            location.href = '/user'
                        }
                    });
                } else if (data.code == -4) { //刷新一下
                    layer.alert(data.msg, {
                        icon: 2, end: function (layero, index) {
                            location.reload();
                        }
                    });
                } else {
                    layer.alert(data.msg, {icon: 3});
                }
            },
            error: function () {
                layer.msg('兑换失败！');
                layer.close(index);
            }
        });
    },
    query_data: function (id) { //查单
        var index = layer.msg('订单查询中...', {icon: 16, time: 9999999});
        $.ajax({
            type: "post",
            url: "ajax.php?act=order_details",
            data: {id: id},
            dataType: "json",
            success: function (data) {
                layer.close(index);
                if (data.code == 1) {
                    data = data.data;
                    var content = '';
                    if (data.ApiType != undefined) {
                        content += '<p style="text-align: center;font-size: 1.3em;color: seagreen;margin-bottom: 0;">订单实时状态</p><table class="layui-table layui-text" lay-size="sm" lay-skin="row"><colgroup>\n' +
                            '    <col width="30%">\n' +
                            '    <col width="50%">' +
                            '    <col width="20%">\n' +
                            '    <col>\n' +
                            '  </colgroup><thead>\n' +
                            '    <tr>\n' +
                            '      <th>类型</th>\n' +
                            '      <th>实时状态</th>' +
                            '      <th>操作</th>\n' +
                            '    </tr> \n' +
                            '  </thead><tbody>';
                        content += '<tr>\n' +
                            '      <td>订单状态</td>\n' +
                            '      <td>' + data.ApiState + '</td>' +
                            '      <td>无</td>\n' +
                            '    </tr>';
                        content += '<tr>\n' +
                            '      <td>初始数量</td>\n' +
                            '      <td>' + data.ApiInitial + '</td>' +
                            '      <td>无</td>\n' +
                            '    </tr>';
                        content += '<tr>\n' +
                            '      <td>下单数量</td>\n' +
                            '      <td>' + data.ApiNum + '</td>' +
                            '      <td>无</td>\n' +
                            '    </tr>';
                        content += '<tr>\n' +
                            '      <td>当前数量</td>\n' +
                            '      <td>' + data.ApiPresent + '</td>' +
                            '      <td>无</td>\n' +
                            '    </tr>';
                        content += '<tr>\n' +
                            '      <td>提交时间</td>\n' +
                            '      <td>' + data.ApiTime + '</td>' +
                            '      <td>无</td>\n' +
                            '    </tr>';
                        if (data.ApiError != '无') {
                            content += '<tr>\n' +
                                '      <td>备注信息</td>\n' +
                                '      <td>' + data.ApiError + '</td>' +
                                '      <td>无</td>\n' +
                                '    </tr>';
                        }
                        content += '</tbody></table><hr>';
                    }
                    content += '<table class="layui-table layui-text" lay-size="sm" lay-skin="row"><colgroup>\n' +
                        '    <col width="30%">\n' +
                        '    <col width="50%">' +
                        '    <col width="20%">\n' +
                        '    <col>\n' +
                        '  </colgroup><thead>\n' +
                        '    <tr>\n' +
                        '      <th>类型</th>\n' +
                        '      <th>状态</th>' +
                        '      <th>操作</th>\n' +
                        '    </tr> \n' +
                        '  </thead><tbody>';

                    content += '<tr>\n' +
                        '      <td>订单编号</td>\n' +
                        '      <td>' + data.order + '</td>' +
                        '      <td>无</td>\n' +
                        '    </tr>';

                    content += '<tr>\n' +
                        '      <td>商品名称</td>\n' +
                        '      <td>' + data.name + '</td>' +
                        '      <td><a href="' + data.url + '" target="_blank">购买</a></td>\n' +
                        '    </tr>';
                    content += '<tr>\n' +
                        '      <td>订单状态</td>\n' +
                        '      <td>' + data.state + '</td>' +
                        '      <td>' + (data.state == '已评价' ? '<a href="javascript:merchandise.mark(' + data.gid + ')">查看</a>' : '无') + '</td>\n' +
                        '    </tr>';
                    content += '<tr>\n' +
                        '      <td>购买数量</td>\n' +
                        '      <td>' + data.num + '</td>' +
                        '      <td>无</td>\n' +
                        '    </tr>';
                    content += '<tr>\n' +
                        '      <td>付款方式</td>\n' +
                        '      <td>' + data.type + '</td>' +
                        '      <td>无</td>\n' +
                        '    </tr>';
                    content += '<tr>\n' +
                        '      <td>支付金额</td>\n' +
                        '      <td>' + (data.price - 0).toFixed(2) + (data.type == '积分兑换' ? '积分' : '元') + '</td>' +
                        '      <td>无</td>\n' +
                        '    </tr>';
                    content += '<tr>\n' +
                        '      <td>下单信息</td>\n' +
                        '      <td>' + data.input + '</td>' +
                        '      <td>无</td>\n' +
                        '    </tr>';

                    content += '<tr>\n' +
                        '      <td>创建时间</td>\n' +
                        '      <td>' + data.addtiem + '</td>' +
                        '      <td>无</td>\n' +
                        '    </tr>';

                    if (data.remark != undefined) {
                        content += '<tr>\n' +
                            '      <td>订单备注</td>\n' +
                            '      <td>' + data.remark + '</td>' +
                            '      <td>无</td>\n' +
                            '    </tr>';
                    }

                    if (data.token_arr != -1) {
                        var token_list = '';
                        $.each(data.token_arr, function (key, val) {
                            token_list += '卡' + (key + 1) + '：' + val + '<br>';
                        });
                        content += '<tr>\n' +
                            '      <td style="color: red">订单卡密</td>\n' +
                            '      <td>' + token_list + '</td>' +
                            '      <td>无</td>\n' +
                            '    </tr>';
                    }

                    content += '</tbody></table><style>#OrderQuery{padding: 0.5em;max-height: 86vh;overflow:hidden;overflow-y: auto}</style><hr>' + data.docs;
                    var area = [$(window).width() > 480 ? '480px' : '98%'];
                    layer.open({
                        type: 0,
                        area: area,
                        title: '订单[' + data.order + ']详情！',
                        content: content,
                        skin: 'layui-layer-rim',
                        id: 'OrderQuery',
                        btn: false,
                    });
                } else {
                    layer.msg(data.msg);
                }
            },
            error: function () {
                layer.alert('查询失败！');
                layer.close(index);
            }
        });
    },
    cid_data: function () { //获取分类数据  通用类
        var index = layer.load(3, {time: 10 * 1000});
        $.ajax({
            type: "post",
            url: "ajax.php?act=getclass",
            dataType: "json",
            success: function (data) {
                layer.close(index);
                if (data.code >= 0) {
                    if (data.data.length == 0) {
                        layer.alert('当前无任何分类', {icon: 2})
                    } else {
                        var content = '';
                        $.each(data.data, function (i, item) {
                            content += template.data_class(item);
                        });
                        $("#cid").html(content);
                        $("#cid").show();
                        setTimeout(function () {
                            operation();
                        }, 300);
                    }
                } else {
                    layer.msg(data.msg);
                }
            },
            error: function () {
                layer.msg('数据获取失败！');
            }
        });
    },
    gid_data: function (cid = null, name = null, type = null, num = -1) { //获取商品数据 通用类
        var url = "ajax.php?act=getgoods";
        var index = layer.load(3, {time: 10 * 1000});
        $.ajax({
            type: "post",
            url: url,
            data: {cid: cid, name: decodeURI(name), num: num},
            dataType: "json",
            success: function (data) {
                layer.close(index);
                if (data.code >= 0) {
                    if (data.data.length == 0) {
                        if (name == null) {
                            layer.msg('当前分类下无任何商品', {icon: 2})
                        } else {
                            layer.msg('没有查询到相关商品', {
                                icon: 2, btn: '返回', btn1: function (layero, index) {
                                    location.href = './';
                                }
                            })
                        }
                    } else {
                        var content = '';
                        $.each(data.data, function (i, item) {
                            content += template.data_goods(item);
                        });
                        $("#gid").html(content);
                        $("#gid").show();
                        if (type == null) {
                            $("#cid").html('');
                        }
                        setTimeout(function () {
                            operation();
                        }, 600);
                        //layer.msg('加载完成,共'+data.data.length+'个商品！',{icon:1});
                    }
                } else {
                    layer.msg(data.msg);
                }
            },
            error: function () {
                layer.msg('数据获取失败！');
            }
        });
    },
    shop_data: function (gid) {
        var index = layer.load(3, {time: 10 * 100000});
        $.ajax({
            type: "post",
            url: "ajax.php?act=getgoods_details",
            data: {
                gid: gid
            },
            dataType: "json",
            success: function (data) {
                layer.close(index);
                if (data.code >= 0) {
                    console.log(data);
                    $("#gootsp").attr({
                        'data-gid': gid,
                        'data-count': data.data['count'],
                        'data-count_quota': data.data['count_quota'],
                        'value': data.data['name'] + ' * 1份 ⇨ ' + data.data['quantity'] + '个',
                        'data-points': data.data['points'],
                        'data-method': data.data.method,
                        'data-image': data.data['image'],
                        'data-currency': data.data['currency'], //货币名称
                        'data-cid': data.data['cid'],
                        'data-price': data.data['price'],
                        'data-level': data.data['level'],
                        'data-pay': data.data['pay'],
                        'data-quantity': data.data['quantity'],
                        'data-picture': data.data['picture'],
                        'data-min': data.data['min'],
                        'data-max': data.data['max'],
                    });

                    var contents = '';
                    count = 1;
                    count_arr = 0;
                    $.each(data.data['level_arr'], function (key, val) {
                        if (count == 1) {
                            tips = '<span style="float:right;margin-right: 1em;" >当前 <font color=red>' + val.price.toFixed(2) + '元</font></span>';
                        } else {
                            tips = '<span style="float:right;margin-right: 1em;color:seagreen;" >' + val.price.toFixed(2) + '元</span>';
                        }
                        contents += '<p>等级：' + val.name + tips + '</p>';
                        ++count;
                        ++count_arr;
                    });
                    if (count_arr > 1) {
                        $("#gootsp").attr({
                            'data-level_arr': escape(contents),
                        });
                    } else {
                        $("#gootsp").attr({
                            'data-level_arr': -1,
                        })
                    }

                    if ((data.data['quantity'] - 0) < (data.data.min - 0)) {
                        var quc = ((data.data.min - 0) / (data.data['quantity'] - 0));
                        layer.msg('此商品最低购买' + quc + '份哦！');
                    }

                    $("#moneys").val((data.data['price'] - 0).toFixed(2) + ' 元');
                    $("#residue").val(data.data['count_quota'] + ' 份');
                    $("#points").val(data.data['points'] + data.data['currency']);
                    $("#classImg").attr('src', data.data['image']);
                    if (data.data['docs'] != '' && data.data['docs'] != 'null' && data.data['docs'] != null && data.data['docs'] != undefined) { //商品说明
                        $("#alert_frame").html(data.data['docs']);
                        $("#alert_frame").show(200);
                    }

                    if (data.data.alert != '' && data.data.alert != 'null' && data.data['alert'] != null && data.data['alert'] != undefined) { //商品弹窗
                        swal({
                            title: '购买须知',
                            type: 'info',
                            html: '<h4>' + data.data['alert'] + '</h4>',
                            animation: false,
                            customClass: 'rubberBand animated',
                            confirmButtonText: '朕已阅',
                        })
                    }
                    /**
                     * 解析下单需填写字段
                     */

                    var method = data.data.method; //商品状态
                    var inputsname = data.data.value;

                    if (method.indexOf(7) != -1) { //是否开启数量选择框和价格监控！
                        temp = '';
                        $('#input_value').append(template.num());
                        if (temp == 'app') {

                            $("#num").bind("input propertychange", function (event) {
                                type = 3;
                                var numt = $("#num").val() - 0;
                                if (numt < 0) {
                                    layer.msg('最低购买一份');
                                    $("#num").val(1);
                                    return false;
                                } else {
                                    value = numt;
                                }

                                $("#num").val(value);
                                ddo = 1;
                                var nums = $("#num").val();
                                if ((nums * (data.data['quantity'] - 0)) < (data.data['min'] - 0) && data.data.min != 0) {
                                    var countes = (data.data['min'] - 0) / (data.data['quantity'] - 0) - 0;
                                    swal({
                                        title: '注意',
                                        type: 'warning',
                                        html: '<h4>商品' + data.data.name + '最少购买' + data.data['min'] + '个(' + (countes <= 1 ? 1 : countes) + '份)！</h4>',
                                        confirmButtonText: '好的',
                                    });
                                    $("#num").val((countes <= 1 ? 1 : countes));
                                    $(".price_app").text('￥' + (data.data['price'] - 0).toFixed(2));
                                    ddo = 2;
                                }

                                if ((nums * (data.data['quantity'] - 0)) > (data.data['max'] - 0) && data.data.max != 0) {
                                    swal({
                                        title: '注意',
                                        type: 'warning',
                                        html: '<h4>商品' + data.data.name + '最多购买' + data.data['max'] + '个(' + (data.data['max'] - 0) / (data.data['quantity'] - 0) + '份)！</h4>',
                                        confirmButtonText: '好的',
                                    });
                                    console.log('123')
                                    //
                                    var pricens = ((data.data['price'] * ((data.data['max'] - 0) / (data.data['quantity'] - 0))).toFixed(2));
                                    $("#num").val((data.data['max'] - 0) / (data.data['quantity'] - 0));
                                    $(".price_app").text('￥' + pricens);
                                    ddo = 2;
                                }

                                var quota = $("#gootsp").attr('data-count_quota') - 0;
                                if ($("#num").val() > quota) {
                                    $("#num").val(quota);
                                    swal({
                                        title: '抱歉,库存不足',
                                        type: 'warning',
                                        html: '<h4>今日库存不足' + value + '份！<br>请减少购买份数！</h4>',
                                        confirmButtonText: '好的',
                                    });
                                    $("#points").val((data.data['points'] * quota).toFixed(0) + data.data['currency']);
                                    $("#gootsp").val(data.data['name'] + ' * ' + quota + '份 ⇨ ' + data.data['quantity'] * quota + '个');
                                    $("#moneys").val((data.data['price'] * quota).toFixed(2) + ' 元');

                                    $(".price_app").text('￥' + (data.data['price'] * quota).toFixed(2));
                                    return false;
                                }

                                if (ddo == 2) return false;

                                if (nums == '' || nums == 0) nums = 0;
                                $("#points").val((data.data['points'] * nums).toFixed(0) + data.data['currency']);
                                $("#gootsp").val(data.data['name'] + ' * ' + nums + '份 ⇨ ' + data.data['quantity'] * nums + '个');
                                $("#moneys").val((data.data['price'] * nums).toFixed(2) + ' 元');

                                $(".price_app").text('￥' + (data.data['price'] * nums).toFixed(2));
                            });

                            $(".numsa").click(function () {
                                type = $(this).attr('data-n') - 0;
                                var numt = $("#num").val() - 0;
                                if (type == 1) {
                                    //减少
                                    if ((numt - 1) < 0) {
                                        layer.msg('最低购买一份');
                                        $("#num").val(1);
                                        return false;
                                    } else {
                                        value = numt - 1;
                                    }
                                } else if (type == 2) {
                                    //增加
                                    value = numt + 1;
                                } else {
                                    //自定义
                                    if (numt < 0) {
                                        layer.msg('最低购买一份');
                                        $("#num").val(1);
                                        return false;
                                    } else {
                                        value = numt;
                                    }
                                }

                                $("#num").val(value);
                                ddo = 1;
                                var nums = $("#num").val();
                                if ((nums * (data.data['quantity'] - 0)) < (data.data['min'] - 0) && data.data.min != 0) {
                                    var countes = (data.data['min'] - 0) / (data.data['quantity'] - 0) - 0;
                                    swal({
                                        title: '注意',
                                        type: 'warning',
                                        html: '<h4>商品' + data.data.name + '最少购买' + data.data['min'] + '个(' + (countes <= 1 ? 1 : countes) + '份)！</h4>',
                                        confirmButtonText: '好的',
                                    });
                                    $(".price_app").text('￥' + (data.data['price'] - 0).toFixed(2));
                                    $("#num").val((countes <= 1 ? 1 : countes));
                                    ddo = 2;
                                }

                                if ((nums * (data.data['quantity'] - 0)) > (data.data['max'] - 0) && data.data.max != 0) {
                                    swal({
                                        title: '注意',
                                        type: 'warning',
                                        html: '<h4>商品' + data.data.name + '最多购买' + data.data['max'] + '个(' + (data.data['max'] - 0) / (data.data['quantity'] - 0) + '份)！</h4>',
                                        confirmButtonText: '好的',
                                    });
                                    $(".price_app").text('￥' + (data.data['price'] * ((data.data['max'] - 0) / (data.data['quantity'] - 0))).toFixed(2));
                                    $("#num").val((data.data['max'] - 0) / (data.data['quantity'] - 0));
                                    ddo = 2;
                                }

                                var quota = $("#gootsp").attr('data-count_quota') - 0;
                                if ($("#num").val() > quota) {
                                    $("#num").val(quota);
                                    swal({
                                        title: '抱歉,库存不足',
                                        type: 'warning',
                                        html: '<h4>今日库存不足' + value + '份！<br>请减少购买份数！</h4>',
                                        confirmButtonText: '好的',
                                    });
                                    $("#points").val((data.data['points'] * quota).toFixed(0) + data.data['currency']);
                                    $("#gootsp").val(data.data['name'] + ' * ' + quota + '份 ⇨ ' + data.data['quantity'] * quota + '个');
                                    $("#moneys").val((data.data['price'] * quota).toFixed(2) + ' 元');

                                    $(".price_app").text('￥' + (data.data['price'] * quota).toFixed(2));

                                    return false;
                                }

                                if (ddo == 2) return false;

                                if (nums == '' || nums == 0) nums = 0;
                                $("#points").val((data.data['points'] * nums).toFixed(0) + data.data['currency']);
                                $("#gootsp").val(data.data['name'] + ' * ' + nums + '份 ⇨ ' + data.data['quantity'] * nums + '个');
                                $("#moneys").val((data.data['price'] * nums).toFixed(2) + ' 元');

                                $(".price_app").text('￥' + (data.data['price'] * nums).toFixed(2));
                            });
                        } else {
                            $("#num").click(function () {
                                var prome = layer.prompt({
                                    formType: 3,
                                    value: $("#num").val(),
                                    title: '填写需要的商品份数',
                                }, function (value, index, elem) {
                                    $("#num").val(value);
                                    ddo = 1;
                                    var nums = $("#num").val();
                                    if ((nums * (data.data['quantity'] - 0)) < (data.data['min'] - 0) && data.data.min != 0) {

                                        var countes = (data.data['min'] - 0) / (data.data['quantity'] - 0);

                                        swal({
                                            title: '注意',
                                            type: 'warning',
                                            html: '<h4>商品' + data.data.name + '最少购买' + data.data['min'] + '个(' + (data.data['min'] - 0) / (countes <= 1 ? 1 : countes) + '份)！</h4>',
                                            confirmButtonText: '好的',
                                        });
                                        $("#num").val((countes <= 1 ? 1 : countes));
                                        $("#moneys").val(data.data['price'] + ' 元');
                                        layer.close(prome);
                                        ddo = 2;
                                    }

                                    if ((nums * (data.data['quantity'] - 0)) > (data.data['max'] - 0) && data.data.max != 0) {
                                        swal({
                                            title: '注意',
                                            type: 'warning',
                                            html: '<h4>商品' + data.data.name + '最多购买' + data.data['max'] + '个(' + (data.data['max'] - 0) / (data.data['quantity'] - 0) + '份)！</h4>',
                                            confirmButtonText: '好的',
                                        });
                                        $("#num").val((data.data['max'] - 0) / (data.data['quantity'] - 0));
                                        $("#moneys").val((data.data['price'] * ((data.data['max'] - 0) / (data.data['quantity'] - 0))).toFixed(2) + ' 元');
                                        layer.close(prome);
                                        ddo = 2;
                                    }

                                    var quota = $("#gootsp").attr('data-count_quota') - 0;
                                    if ($("#num").val() > quota) {
                                        $("#num").val(quota);
                                        swal({
                                            title: '抱歉,库存不足',
                                            type: 'warning',
                                            html: '<h4>今日库存不足' + value + '份！<br>请减少购买份数！</h4>',
                                            confirmButtonText: '好的',
                                        });
                                        $("#points").val((data.data['points'] * quota).toFixed(0) + data.data['currency']);
                                        $("#gootsp").val(data.data['name'] + ' * ' + quota + '份 ⇨ ' + data.data['quantity'] * quota + '个');
                                        $("#moneys").val((data.data['price'] * quota).toFixed(2) + ' 元');

                                        $(".price_app").text('￥' + (data.data['price'] * quota).toFixed(2));

                                        layer.close(prome);
                                        return false;
                                    }

                                    if (ddo == 2) return false;

                                    if (nums == '' || nums == 0) nums = 0;
                                    $("#points").val((data.data['points'] * nums).toFixed(0) + data.data['currency']);
                                    $("#gootsp").val(data.data['name'] + ' * ' + nums + '份 ⇨ ' + data.data['quantity'] * nums + '个');
                                    $("#moneys").val((data.data['price'] * nums).toFixed(2) + ' 元');

                                    $(".price_app").text('￥' + (data.data['price'] * nums).toFixed(2));
                                    layer.close(prome);
                                });
                            })
                        }
                    }
                    if (inputsname == '') {
                        inputsname = '下单ＱＱ';
                    }
                    if (inputsname != '') {
                        $.each(inputsname.split('|'), function (i, value) {
                            if (value.indexOf('{') > 0 && value.indexOf('}') > 0) {
                                var addstr = '';
                                var selectname = value.split('{')[0];
                                var selectstr = value.split('{')[1].split('}')[0];
                                $.each(selectstr.split(','), function (i, v) {
                                    if (v.indexOf(':') > 0) {
                                        i = v.split(':')[0];
                                        v = v.split(':')[1];
                                    } else {
                                        i = v;
                                    }
                                    addstr += '<option value="' + i + '">' + v + '</option>';
                                });
                                $('#input_value').append(template.select_data(selectname, addstr, (i + 1)));
                            } else {
                                if (value == '说说ID' || value == '说说ＩＤ')
                                    var addstr = '<div class="layui-btn layui-btn-sm layui-btn-normal btnee" onclick="get_shuoshuo(\'input_val_' + (i + 1) + '\',$(\'#input_val_' + (i) + '\').val())">自动获取</div>'; //已搞定
                                else if (value == '作品ID' || value == '作品ＩＤ' || value == '快手作品ID')
                                    var addstr = '<div class="layui-btn layui-btn-sm layui-btn-normal btnee" onclick="get_kuaishou(\'input_val_' + (i + 1) + '\',\'input_val_' + (i) + '\')">自动获取</div>'; //已搞定
                                else if (value == '签收' || value == '寄送' || value == '地址' || value == '收货地址' || value == '收货人地址' || value == '地址信息' || value == '联系地址' || value == '家庭地址') {
                                    var addstr = '<div class="layui-btn layui-btn-sm layui-btn-normal btnee" onclick="getCity(\'input_val_' + (i + 1) + '\')">点此选择</div>';
                                    //调用运费模板配置
                                    if (data['freight'] != '-1') {
                                        data.data['CarriageTem'] = 'input_val_' + (i + 1);
                                    }
                                } else
                                    var addstr = '';
                                $('#input_value').append(template.input_data(value, placeholder_auto(value), i + 1, addstr));
                            }
                        });
                    }

                    if (data['freight'] != '-1' && data.data['CarriageTem'] == undefined) {
                        data.data['CarriageTem'] = 'input_val_1';
                    }

                    if (method.indexOf(1) != -1 || method.indexOf(2) != -1) { //是否关闭金额显示！
                        $("#moneys_os").show(10);
                    }
                    if (method.indexOf(3) != -1) { //是否关闭积分显示！
                        $("#points_os").show();
                    }
                    $("#repertory").show();
                    layui.use('form', function () {
                        var form = layui.form;
                        form.render();
                    });
                    template.success(data); //商品数据加载完成后执行
                    merchandise.GoodsMonitoring(gid);
                    return true;
                } else layer.msg(data.msg);
            },
            error: function () {
                layer.msg('数据获取失败！');
            }
        });
    }
    , GoodsMonitoring: function (gid) {
        $.ajax({
            type: "post",
            url: "ajax.php?act=GoodsMonitoring",
            data: {
                gid: gid
            },
            dataType: "json",
            success: function (data) {
                if (data.code == -1) {
                    layer.alert(data.msg, {
                        icon: 1, title: false, btn1: function (layero, index) {
                            location.reload();
                        }
                    });
                }
            }
        });
    }
};

var CarriageTem = {
    start: function (id, data, price) {
        setInterval(function () {
            CarriageTem.matching($("#" + id).val(), data, price);
        }, 1000);
    }, matching: function (val, data, price) {
        var num = ($('#num').val() == undefined ? 1 : $('#num').val() - 0);
        if ($("#matching_msg").attr('data-value') != undefined && $("#matching_msg").attr('data-num') != undefined) {
            if ($("#matching_msg").attr('data-value') == val && $("#matching_msg").attr('data-num') == num) return false;
        }
        $("#matching_msg").attr({
            'data-value': val,
            'data-num': num
        });
        var arr_region = data['region'].split('|');
        var matching_region = false;
        $.each(arr_region, function (index, value) {
            if (matching_region == false) matching_region = CarriageTem.matching_region(value, val);
        });

        if (matching_region != false) {
            data['exceed'] = matching_region[2];
            data['money'] = matching_region[1];
            data['regionarr'] = matching_region[0];
        }

        if ((price * num).toFixed(2) >= (data['threshold'] - 0)) {
            CarriageTem.matching_msg(0, '您需付款的金额已经高出<font color="#ff6347">' + data['threshold'] + '</font>元,已经帮您免除运费！');
            return false;
        }
        if (num <= (data['nums'] - 0)) {
            var money = data['money'];
            if (data['regionarr'] != undefined) {
                CarriageTem.matching_msg(money, '<font color="#40e0d0">' + data['regionarr'] + '地区</font>用户购买此商品需额外缴纳<font color="red">' + money + '</font>元运费<br>如果付款金额超出<font color="red">' + data['threshold'] + '</font>元可免除运费哦~');
            } else {
                CarriageTem.matching_msg(money, '购买此商品需额外缴纳<font color="red">' + money + '</font>元运费<br>如果付款金额超出<font color="red">' + data['threshold'] + '</font>元可免除运费哦~');
            }
        } else {
            var money = ((num - (data['nums'] - 0)) * data['exceed']).toFixed(2);
            if (data['regionarr'] != undefined) {
                CarriageTem.matching_msg((money + data['money']), '<font color="#40e0d0">' + data['regionarr'] + '地区</font>用户购买此商品需额外缴纳<font color="red">' + data['money'] + '</font>元运费<br>您已超出<font color="red">' + (num - (data['nums'] - 0)) + '</font>份<br>需额外加<font color="red">' + money + '</font>元运费！<br>每超出1件加<font color="red">' + data['exceed'] + '</font>元！');
            } else {
                CarriageTem.matching_msg((money + data['money']), '购买此商品需额外缴纳<font color="red">' + data['money'] + '</font>元运费<br>您已超出<font color="red">' + (num - (data['nums'] - 0)) + '</font>份,需额外加<font color="red">' + money + '</font>元运费！<br>每超出1份需加<font color="red">' + data['exceed'] + '</font>元！');
            }
        }
    },
    matching_region: function (arr_rage, val) {
        var arr_rage = arr_rage.split(',');
        if (val.indexOf(arr_rage[0]) != -1) {
            return arr_rage;
        } else {
            return false;
        }
    },
    matching_msg(money = 0, msg) {
        $("#matching_msg").show(100);
        $("#matching_msg").html(msg);
        $("#matching_msg").attr({
            'data-price': money,
        });
    }
};

$(".picture_img").click(function () {
    alert('picture_img');
    console.log(this.src)
});

function operation() { //完成后的操作
    layui.use('flow', function () {
        var flow = layui.flow;
        flow.lazyimg();
    });
}

function checkInput(name_id, value_id) { //二次解析

    if ($("#" + name_id).html() == '抖音ＩＤ' || $("#" + name_id).html() == '抖音视频ＩＤ' || $("#" + name_id).html() == '抖音ID') {
        if ($("#" + value_id).val() != '' && $("#" + value_id).val().indexOf('http') >= 0) {
            getshareid(value_id);
        }
    } else if ($("#" + name_id).html() == '火山ID' || $("#" + name_id).html() == '火山作品ID' || $("#" + name_id).html() == '火山视频ID' || $("#" + name_id).html() == '火山ＩＤ') {
        if ($("#" + value_id).val() != '' && $("#" + value_id).val().indexOf('http') >= 0) {
            gethuoshanid(value_id);
        }
    } else if ($("#" + name_id).html() == '微视ID' || $("#" + name_id).html() == '微视作品ID' || $("#" + name_id).html() == '微视ＩＤ' || $("#" + name_id).html() == '微视主页ID') {
        if ($("#" + value_id).val() != '' && $("#" + value_id).val().indexOf('http') >= 0) {
            getweishiid(value_id);
        }
    } else if ($("#" + name_id).html() == '头条ID' || $("#" + name_id).html() == '头条ＩＤ') {
        if ($("#" + value_id).val() != '' && $("#" + value_id).val().indexOf('http') >= 0) {
            gettoutiaoid(value_id);
        }
    } else if ($("#" + name_id).html() == '小红书ID' || $("#" + name_id).html() == '小红书作品ID' || $("#" + name_id).html() == '皮皮虾ID' || $("#" + name_id).html() == '皮皮虾作品ID') {
        if ($("#" + value_id).val() != '' && $("#" + value_id).val().indexOf('http') >= 0) {
            getxiaohongshuid(value_id);
        }
    } else if ($("#" + name_id).html() == '美拍ID' || $("#" + name_id).html() == '美拍ＩＤ' || $("#" + name_id).html() == '美拍作品ID' || $("#" + name_id).html() == '美拍视频ID') {
        if ($("#" + value_id).val() != '' && $("#" + value_id).val().indexOf('http') >= 0) {
            getmeipaiid(value_id);
        }
    } else if ($("#" + name_id).html() == '哔哩哔哩视频ID' || $("#" + name_id).html() == '哔哩哔哩ID' || $("#" + name_id).html() == '哔哩视频ID') {
        if ($("#" + value_id).val() != '' && $("#" + value_id).val().indexOf('http') >= 0) {
            getbilibiliid(value_id);
        }
    } else if ($("#" + name_id).html() == '最右帖子ID') {
        if ($("#" + value_id).val() != '' && $("#" + value_id).val().indexOf('http') >= 0) {
            getzuiyouid(value_id);
        }
    } else if ($("#" + name_id).html() == '全民ID' || $("#" + name_id).html() == '全民K歌ID') {
        if ($("#" + value_id).val() != '' && $("#" + value_id).val().indexOf('http') >= 0) {
            getquanminid(value_id);
        }
    } else if ($("#" + name_id).html() == '美图作品ID' || $("#" + name_id).html() == '美图视频ID') {
        if ($("#" + value_id).val() != '' && $("#" + value_id).val().indexOf('http') >= 0) {
            getmeituid(value_id);
        }
    } else if ($("#" + name_id).html() == '绿洲作品ID' || $("#" + name_id).html() == '绿洲视频ID') {
        if ($("#" + value_id).val() != '' && $("#" + value_id).val().indexOf('http') >= 0) {
            getoasisid(value_id);
        }
    } else if ($("#" + name_id).html() == '视频链接' || $("#" + name_id).html() == '作品链接' || $("#" + name_id).html() == '分享链接') {
        if ($("#" + value_id).val() != '' && $("#" + value_id).val().indexOf('http') >= 0) {
            getsharelink(value_id);
        }
    }
}

function getshareid(value_id) {
    var input_id = value_id.split('_');
    var songurl = $("#" + value_id).val();
    if (songurl == '') {
        layer.alert('请确保每项不能为空！');
        return false;
    }
    if (songurl.indexOf('http') < 0) {
        layer.alert('请输入正确的内容！');
        return false;
    }
    try {
        if (songurl.indexOf('http://') >= 0) {
            var songurl = 'http://' + songurl.split('http://')[1].split(' ')[0].split('，')[0];
        } else if (songurl.indexOf('https://') >= 0) {
            var songurl = 'https://' + songurl.split('https://')[1].split(' ')[0].split('，')[0];
        } else {
            throw false;
        }
        var ii = layer.load(2, {shade: [0.1, '#fff']});
        $.ajax({
            type: "POST",
            url: "ajax.php?act=getshareid",
            data: {url: songurl},
            dataType: 'json',
            success: function (data) {
                layer.close(ii);
                if (data.code == 0) {
                    if (typeof data.songid != "undefined" && $('#' + value_id).length > 0) $('#' + value_id).val(data.songid);
                    layer.msg('ID获取成功！下单即可', {icon: 1});
                } else {
                    layer.alert(data.msg);
                    return false;
                }
            }
        });
    } catch (e) {
        layer.alert('请输入正确的内容！');
        return false;
    }
}

function gethuoshanid(value_id) {
    var songurl = $("#" + value_id).val();
    if (songurl == '') {
        layer.alert('请确保每项不能为空！');
        return false;
    }
    if (songurl.indexOf('.huoshan.com') < 0) {
        layer.alert('请输入正确的链接！');
        return false;
    }
    if (songurl.indexOf('/s/') > 0) {
        var ii = layer.load(2, {shade: [0.1, '#fff']});
        $.ajax({
            type: "POST",
            url: "ajax.php?act=gethuoshan",
            data: {url: songurl},
            dataType: 'json',
            success: function (data) {
                layer.close(ii);
                if (data.code == 0) {
                    $('#' + value_id).val(data.songid);
                    layer.msg('火山小视频ID获取成功', {icon: 1})
                } else {
                    layer.alert(data.msg, {icon: 2});
                    return false;
                }
            }
        });
    } else {
        try {
            if (songurl.indexOf('video/') > 0) {
                var songid = songurl.split('video/')[1].split('/')[0];
            } else if (songurl.indexOf('item/') > 0) {
                var songid = songurl.split('item/')[1].split('/')[0];
            } else if (songurl.indexOf('room/') > 0) {
                var songid = songurl.split('room/')[1].split('/')[0];
            } else {
                var songid = songurl.split('user/')[1].split('/')[0];
            }
            layer.msg('ID获取成功！下单即可');
        } catch (e) {
            layer.alert('请输入正确的链接！');
            return false;
        }
        $('#' + value_id).val(songid);
    }
}

function getweishiid(value_id) {
    var songurl = $("#" + value_id).val();
    if (songurl == '') {
        layer.alert('请确保每项不能为空！');
        return false;
    }
    if (songurl.indexOf('.qq.com') < 0) {
        layer.alert('请输入正确的链接！');
        return false;
    }
    try {
        if (songurl.indexOf('feed/') > 0) {
            var songid = songurl.split('feed/')[1].split('/')[0];
        } else if (songurl.indexOf('personal/') > 0) {
            var songid = songurl.split('personal/')[1].split('/')[0];
        } else {
            var songid = songurl.split('id=')[1].split('&')[0];
        }
        layer.msg('ID获取成功！下单即可', {icon: 1});
    } catch (e) {
        layer.alert('请输入正确的链接！');
        return false;
    }
    $('#' + value_id).val(songid);
}

function gettoutiaoid(value_id) {
    var songurl = $("#" + value_id).val();
    if (songurl == '') {
        layer.alert('请确保每项不能为空！');
        return false;
    }
    if (songurl.indexOf('.toutiaocdn.com') < 0) {
        layer.alert('请输入正确的链接！');
        return false;
    }
    try {
        if (songurl.indexOf('group/') > 0) {
            var songid = songurl.split('group/')[1].split('/')[0];
        } else {
            var songid = songurl.split('group_id=')[1].split('=')[0];
        }
        layer.msg('ID获取成功！下单即可', {icon: 1});
    } catch (e) {
        layer.alert('请输入正确的链接！');
        return false;
    }
    $('#' + value_id).val(songid);
}

function getxiaohongshuid(value_id) {
    var songurl = $("#" + value_id).val();
    if (songurl == '') {
        layer.alert('请确保每项不能为空！');
        return false;
    }
    if (songurl.indexOf('/t.cn/') > 0 || songurl.indexOf('/xhsurl.com/') > 0) {
        var ii = layer.load(2, {shade: [0.1, '#fff']});
        $.ajax({
            type: "POST",
            url: "ajax.php?act=getxiaohongshu",
            data: {url: songurl},
            dataType: 'json',
            success: function (data) {
                layer.close(ii);
                if (data.code == 0) {
                    $('#' + value_id).val(data.songid);
                    layer.msg('小红书ID获取成功！下单即可', {icon: 1});
                } else {
                    layer.alert(data.msg);
                    return false;
                }
            }
        });
    } else {
        if (songurl.indexOf('xiaohongshu.com') < 0 && songurl.indexOf('pipix.com') < 0) {
            layer.alert('请输入正确的链接！');
            return false;
        }
        try {
            var songid = songurl.split('item/')[1].split('?')[0];
            layer.msg('小红书ID获取成功！下单即可', {icon: 1});
        } catch (e) {
            layer.alert('请输入正确的链接！');
            return false;
        }
    }
    $('#' + value_id).val(songid);
}

function getmeipaiid(value_id) {
    var songurl = $("#" + value_id).val();
    if (songurl == '') {
        layer.alert('请确保每项不能为空！');
        return false;
    }
    if (songurl.indexOf('meipai.com') < 0) {
        layer.alert('请输入正确的视频链接！');
        return false;
    }
    if (songurl.indexOf('/s/') > 0) {
        var ii = layer.load(2, {shade: [0.1, '#fff']});
        $.ajax({
            type: "POST",
            url: "ajax.php?act=gethuoshan",
            data: {url: songurl},
            dataType: 'json',
            success: function (data) {
                layer.close(ii);
                if (data.code == 0) {
                    $('#' + value_id).val(data.songid);
                    layer.msg('ID获取成功！下单即可', {icon: 1});
                } else {
                    layer.alert(data.msg);
                    return false;
                }
            }
        });
    } else {
        try {
            var songid = songurl.split('media/')[1].split('?')[0];
            layer.msg('ID获取成功！下单即可', {icon: 1});
        } catch (e) {
            layer.alert('请输入正确的视频链接！');
            return false;
        }
    }
    $('#' + value_id).val(songid);
}

function getbilibiliid(value_id) {
    var songurl = $("#" + value_id).val();
    if (songurl == '') {
        layer.alert('请确保每项不能为空！');
        return false;
    }
    if (songurl.indexOf('bilibili.com') < 0 && songurl.indexOf('b23.tv') < 0) {
        layer.alert('请输入正确的视频链接！');
        return false;
    }
    try {
        if (songurl.indexOf('bilibili.com') > 0) {
            var songid = songurl.split('video/av')[1].split('/')[0];
        } else {
            var songid = songurl.split('/av')[1].split('/')[0];
        }
        layer.msg('ID获取成功！下单即可', {icon: 1});
    } catch (e) {
        layer.alert('请输入正确的视频链接！');
        return false;
    }
    $('#' + value_id).val(songid);
}

function getzuiyouid(value_id) {
    var songurl = $("#" + value_id).val();
    if (songurl == '') {
        layer.alert('请确保每项不能为空！');
        return false;
    }
    if (songurl.indexOf('izuiyou.com') < 0) {
        layer.alert('请输入正确的帖子链接！');
        return false;
    }
    try {
        var songid = songurl.split('detail/')[1].split('?')[0];
        layer.msg('ID获取成功！下单即可', {icon: 1});
    } catch (e) {
        layer.alert('请输入正确的帖子链接！');
        return false;
    }
    $('#' + value_id).val(songid);
}

function getquanminid(value_id) {
    var songurl = $("#" + value_id).val();
    if (songurl == '') {
        layer.alert('请确保每项不能为空！');
        return false;
    }
    if (songurl.indexOf('kg2.qq.com') < 0) {
        layer.alert('请输入正确的视频链接！');
        return false;
    }
    try {
        var songid = songurl.split('play?s=')[1].split('&shareuid')[0];
        layer.msg('ID获取成功！下单即可', {icon: 1});
    } catch (e) {
        layer.alert('请输入正确的视频链接！');
        return false;
    }
    $('#' + value_id).val(songid);
}

function getmeituid(value_id) {
    var songurl = $("#" + value_id).val();
    if (songurl == '') {
        layer.alert('请确保每项不能为空！');
        return false;
    }
    if (songurl.indexOf('meitu.com') < 0) {
        layer.alert('请输入正确的视频链接！');
        return false;
    }
    try {
        var songid = songurl.split('feed_id=')[1].split('&')[0];
        layer.msg('ID获取成功！下单即可', {icon: 1});
    } catch (e) {
        layer.alert('请输入正确的视频链接！');
        return false;
    }
    $('#' + value_id).val(songid);
}

function getoasisid(value_id) {
    var songurl = $("#" + value_id).val();
    if (songurl == '') {
        layer.alert('请确保每项不能为空！');
        return false;
    }
    if (songurl.indexOf('weibo.cn') < 0 && songurl.indexOf('weibo.com') < 0) {
        layer.alert('请输入正确的视频链接！');
        return false;
    }
    try {
        var songid = songurl.split('sid=')[1].split('&')[0];
        layer.msg('ID获取成功！下单即可', {icon: 1});
    } catch (e) {
        layer.alert('请输入正确的视频链接！');
        return false;
    }
    $('#' + value_id).val(songid);
}

function getsharelink(value_id) {
    var songurl = $("#" + value_id).val();
    if (songurl == '') {
        layer.alert('请确保每项不能为空！');
        return false;
    }
    if (songurl.indexOf('http') < 0) {
        layer.alert('请输入正确的内容！');
        return false;
    }
    try {
        if (songurl.indexOf('http://') >= 0) {
            var songid = 'http://' + songurl.split('http://')[1].split(' ')[0].split('，')[0];
        } else if (songurl.indexOf('https://') >= 0) {
            var songid = 'https://' + songurl.split('https://')[1].split(' ')[0].split('，')[0];
        }
        if (songid != $("#" + value_id).val()) layer.msg('链接转换成功！下单即可');
    } catch (e) {
        layer.alert('请输入正确的内容！');
        return false;
    }
    $('#' + value_id).val(songid);
}


function get_shuoshuo(id, uin, km, page) {
    km = km || 0;
    page = page || 1;
    if (uin == '') {
        layer.alert('请先填写ＱＱ号！');
        return false;
    }
    var ii = layer.load(2, {shade: [0.1, '#fff']});
    $.ajax({
        type: "GET",
        url: "ajax.php?act=getshuoshuo&uin=" + uin + "&page=" + page,
        dataType: 'json',
        success: function (data) {
            layer.close(ii);
            if (data.code >= 0) {
                var addstr = '<div class="layui-row layui-col-space15">';
                $.each(data.data, function (i, item) {
                    if (item['content'] == null) {
                        item['content'] = '';
                    }
                    if (item.image == '') {
                        image = '';
                    } else {
                        image = '';
                        $.each(item.image, function (s, images) {
                            image += '<img class="layui-col-xs4" src="' + images + '" />';
                        })
                    }
                    addstr += '' +
                        '<div class="layui-col-xs6 layui-col-sm5 layui-col-md3" onclick="insertion(\'' + item['ssid'] + '\',\'' + id + '\')">' +
                        '<div class="layui-card" style="cursor: pointer;box-shadow: 3px 3px 16px #ccc;border-radius: 0.5em">' +
                        '<div class="layui-card-hader layui-elip bg-cyan" style="text-align: center;color: white;background: linear-gradient(to right, #ff4e50, #f9d423)">' + item['name'] + '发布于：' + item['addtime'] + '</div>' +
                        '<div class="layui-card-body">' +
                        '<div class="layui-text">' + item['content'] + '</div>' +
                        '<div class="layui-row layui-col-space1">' + image + '</div>' +
                        '</div>' +
                        '</div>' +
                        '</div>';
                });
                addstr += '</div>';
                if (addstr == '<div class="layui-row layui-col-space15"></div>') {
                    layer.alert('请先发布一条说说', {icon: 2});
                    return false;
                }
                var nextpage = page + 1;
                var lastpage = page > 1 ? page - 1 : 1;
                layer.open({
                    title: 'ＱＱ' + uin + '的说说,点击说说选择~'
                    , content: addstr
                    , area: ['96%', '96%']
                    , btnAlign: 'c'
                    , btn: ['关闭', '上一页', '下一页']
                    , btn2: function f(layero, index) {
                        get_shuoshuo(id, uin, km, lastpage)
                    }, btn3: function f(layero, index) {
                        get_shuoshuo(id, uin, km, nextpage)
                    }
                });
            } else {
                layer.alert(data.msg);
            }
        }
    });
}

function get_kuaishou(id, ksid) {
    if (ksid == '') {
        ksid = $('#' + ksid).val();
        if (ksid == '') {
            layer.alert('请先填写作品链接！');
            return false;
        }
    }
    var zpid = $('#' + ksid).val();
    if (ksid.indexOf('http') >= 0) {
        var kuauishouurl = ksid;
    } else if (zpid.indexOf('http') >= 0) {
        var kuauishouurl = zpid;
    } else if (zpid == '') {
        layer.alert('请先填写作品链接！');
        return false;
    } else {
        return true;
    }
    if (kuauishouurl.indexOf('http') < 0) {
        layer.alert('请输入正确的KF作品链接！');
        return false;
    }
    if (kuauishouurl.indexOf('/s/') > 0) {
        var ii = layer.load(2, {shade: [0.1, '#fff']});
        $.ajax({
            type: "POST",
            url: "ajax.php?act=getkuaishou",
            data: {url: kuauishouurl},
            dataType: 'json',
            success: function (data) {
                layer.close(ii);
                if (data.code == 0) {
                    $('#' + ksid).val(data.authorid);
                    $('#' + id).val(data.videoid);
                    layer.msg('ID获取成功！下单即可', {icon: 1});
                } else {
                    layer.alert(data.msg);
                    return false;
                }
            }
        });
    } else if (kuauishouurl.indexOf('kuaishou.com') > 0) {
        var kuais_id = 1;
        var ii = layer.load(2, {shade: [0.1, '#fff']});
        $.ajax({
            type: "POST",
            url: "ajax.php?act=getkuaishou2",
            data: {url: kuauishouurl},
            dataType: 'json',
            success: function (data) {
                layer.close(ii);
                if (data.code == 0) {
                    $('#' + ksid).val(data.authorid);
                    $('#' + id).val(data.videoid);
                    layer.msg('ID获取成功！下单即可', {icon: 1});
                } else {
                    layer.alert(data.msg);
                    return false;
                }
            }
        });
    } else {
        try {
            if (kuauishouurl.indexOf('userId=') > 0) {
                var authorid = kuauishouurl.split('userId=')[1].split('&')[0];
            } else {
                var authorid = kuauishouurl.split('photo/')[1].split('/')[0];
            }
            if (kuauishouurl.indexOf('photoId=') > 0) {
                var videoid = kuauishouurl.split('photoId=')[1].split('&')[0];
            } else {
                var videoid = kuauishouurl.split('photo/')[1].split('/')[1].split('?')[0];
            }
            layer.msg('ID获取成功！下单即可');
        } catch (e) {
            layer.alert('请输入正确的作品链接！');
            return false;
        }
        $('#' + ksid).val(authorid);
        $('#' + id).val(videoid);
    }
}

function getCity(inputid, fid, i) {
    i = i || 0;
    fid = fid || 0;
    if (i == 0) {
        var options = '<select class="form-control" id="biaozhi_' + (i + 1) + '" onchange="getCity(\'' + inputid + '\',this.value,' + (i + 1) + ')">';
        options += '<option>请选择地址</option>';
        $.each("\u5317\u4eac|1|72|1,\u4e0a\u6d77|2|78|1,\u5929\u6d25|3|51035|1,\u91cd\u5e86|4|113|1,\u6cb3\u5317|5|142,\u5c71\u897f|6|303,\u6cb3\u5357|7|412,\u8fbd\u5b81|8|560,\u5409\u6797|9|639,\u9ed1\u9f99\u6c5f|10|698,\u5185\u8499\u53e4|11|799,\u6c5f\u82cf|12|904,\u5c71\u4e1c|13|1000,\u5b89\u5fbd|14|1116,\u6d59\u6c5f|15|1158,\u798f\u5efa|16|1303,\u6e56\u5317|17|1381,\u6e56\u5357|18|1482,\u5e7f\u4e1c|19|1601,\u5e7f\u897f|20|1715,\u6c5f\u897f|21|1827,\u56db\u5ddd|22|1930,\u6d77\u5357|23|2121,\u8d35\u5dde|24|2144,\u4e91\u5357|25|2235,\u897f\u85cf|26|2951,\u9655\u897f|27|2376,\u7518\u8083|28|2487,\u9752\u6d77|29|2580,\u5b81\u590f|30|2628,\u65b0\u7586|31|2652,\u6e2f\u6fb3|52993|52994,\u53f0\u6e7e|32|2768,\u9493\u9c7c\u5c9b|84|84".split(","), function (a, c) {
            c = c.split("|"),
                options += '<option value="' + c[1] + '">' + c[0] + '</option>'
        });
        options += '</select>';
        layer.alert('<div id="layer_button">' + options + '</div>', {icon: 3, title: '地址选择'}, function (index) {
            var con = '';
            $("#layer_button select").each(function () {
                con += $(this.options[this.selectedIndex]).text();
            });
            if ($("#more_dizhi").length > 0) con += $("#more_dizhi").val();
            if (con.length < 7) return layer.alert('请选择完整的收货地址！');
            $("#" + inputid).val(con).show();
            $("#button_" + inputid).hide();
            layer.close(index);
        });
    } else {
        $.ajax({
            type: "get",
            url: "https://fts.jd.com/area/get?fid=" + fid,
            dataType: "jsonp",
            success: function (data) {
                if (data.length < 1) {
                    if ($("#layer_button").html().indexOf("getCity('" + inputid + "',this.value," + (i + 1) + ")") != -1) {
                        $("#biaozhi_" + (i + 1)).remove();
                    }
                    if ($("#more_dizhi").length > 0) {
                    } else $("#layer_button").append('<input class="form-control" id="more_dizhi" placeholder="详细地址(村、门牌号)">');
                    return false;
                }
                var options = '<select class="form-control" id="biaozhi_' + (i + 1) + '" onchange="getCity(\'' + inputid + '\',this.value,' + (i + 1) + ')">';
                options += '<option>请选择地址</option>';
                $.each(data, function (index, res) {
                    options += '<option value="' + res.id + '">' + res.name + '</option>';
                });
                options += '</select>';
                if ($("#layer_button").html().indexOf("getCity('" + inputid + "',this.value," + (i + 1) + ")") != -1) {
                    $("#more_dizhi").remove();
                    $("#biaozhi_" + (i + 1)).html(options);
                } else {
                    $("#layer_button").append(options);
                }
            }
        });
    }
}

function insertion(v, id) { //插入
    $('#' + id).val(v);
    layer.closeAll();
    layer.msg('数据插入成功', {icon: 1});
}

function placeholder_auto(inputname) { //可自动匹配提示语
    switch (inputname) {
        case '说说ID':
        case '说说ＩＤ':
            return '上方填写ＱＱ账号后点击→';
            break;
        case '抖音ＩＤ':
        case '抖音视频ＩＤ':
        case '抖音ID':
            return '在此输入分享链接 可自动获取';
            break;
        case '火山ID':
        case '火山作品ID':
        case '火山视频ID':
        case '火山作品ID':
        case '火山ＩＤ':
        case '火山作品ＩＤ':
            return '在此输入火山视频的链接 可自动获取';
            break;
        case '微视ID':
        case '微视作品ID':
        case '微视ＩＤ':
            return '在此输入微视的作品链接 可自动获取';
            break;
        case '小红书ID':
        case '小红书作品ID':
        case '小红书ＩＤ':
            return '在此输入小红书的作品链接 可自动获取';
            break;
        case '皮皮虾ID':
        case '皮皮虾作品ID':
            return '在此输入皮皮虾的作品链接 可自动获取';
            break;
        case '微视主页ID':
            return '在此输入微视的主页链接 可自动获取';
            break;
        case '头条ID':
        case '头条ＩＤ':
            return '在此输入今日头条的链接 可自动获取';
            break;
        case '美拍ID':
        case '美拍ＩＤ':
        case '美拍作品ID':
        case '美拍视频ID':
            return '在此输入美拍视频链接 可自动获取';
            break;
        case '哔哩哔哩视频ID':
        case '哔哩哔哩ID':
        case '哔哩视频ID':
            return '在此输入哔哩哔哩视频链接 可自动获取';
            break;
        case '最右帖子ID':
            return '在此输入最右帖子链接 可自动获取';
            break;
        case '全民视频ID':
        case '全民小视频ID':
            return '在此输入全民小视频链接 可自动获取';
            break;
        case '美图作品ID':
        case '美图视频ID':
            return '在此输入美图作品链接 可自动获取';
            break;
        case '绿洲作品ID':
        case '绿洲视频ID':
            return '在此输入绿洲作品分享链接 可自动获取';
            break;
        case '作品链接':
        case '视频链接':
        case '分享链接':
            return '在此输入复制后的链接 可自动转换';
            break;
        default:
            return '请将' + inputname + '填写完整！';
            break;
    }
}


